package com.kll.tv.views

import android.view.View
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import com.kll.carolinehmibiz.base.utils.L
import com.kll.carolinehmibiz.presentation.listener.DiseaseDetailsProtocol
import com.kll.carolinehmibiz.presentation.presenter.DiseaseDetailsPresenter
import com.kll.tv.base.views.BaseActivity
import com.kll.tv.databinding.ActivityDiseasDetailsBinding

/**
 * 疾病详情页
 */
class DiseaseDetailsActivity: BaseActivity<DiseaseDetailsPresenter>(), DiseaseDetailsProtocol.IView {
    private lateinit var binding: ActivityDiseasDetailsBinding
    private var url = ""
    private var title = ""

    override fun initViewBinding(): View {
        binding = ActivityDiseasDetailsBinding.inflate(layoutInflater)
        return binding.root
    }

    override fun createPresenter(): DiseaseDetailsPresenter {
        return DiseaseDetailsPresenter(this, this)
    }

    override fun init() {
        url = intent.getStringExtra("url")!!
        L.d("TAG", "initurl1: ${url}")

        title = intent.getStringExtra("title")!!


        binding.tvTitle.text = title
        binding.wvContent.loadUrl(url)
        binding.wvContent.reload()//update by rxwu ,修改webview缓存的问题
        binding.wvContent.webViewClient = object : WebViewClient() {
            override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
                // view?.loadUrl(url)
                return super.shouldOverrideUrlLoading(view, url)
            }
        }
        binding.wvContent.settings.textZoom = 100
        binding.wvContent.settings.useWideViewPort = true // 扩大比例的缩放
        binding.wvContent.settings.loadWithOverviewMode = true // 自适应屏幕
        binding.wvContent.settings.layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN // 自适应屏幕
        binding.wvContent.settings.setSupportZoom(true)
        binding.wvContent.settings.javaScriptEnabled = true // 启用js
        binding.wvContent.settings.domStorageEnabled = true // 启用domStorage
        binding.wvContent.settings.setAppCacheEnabled(false) // 启用本地缓存


        initListener()
    }

    private fun initListener() {
        binding.ivBack.setOnClickListener {
            finish()
        }
        binding.ivBackCircular.setOnClickListener {
            finish()
        }
    }

}